package com.ssm.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ssm.bean.StockRecord;
import com.ssm.service.StockRecordQueryService;

/**
 * @author ZhaoXianming
 * @Description 库存查询  	
 * @date 2020年3月12日
 */
@Controller
@RequestMapping("/stockRecordQuery")
public class StockQueryController {

	Logger log = LoggerFactory.getLogger(StockQueryController.class);
	
	@Autowired
	public StockRecordQueryService stockRecordQueryService;
	
	@RequestMapping("/toStockQueryJsp")
	public String toJsp(){
		return "stockQuery/stockRecordQuery";
	}
	
	@RequestMapping("/queryStockRecord/{pageNo}/{pageSize}")
	@ResponseBody
	public Map<String,Object> queryStockRecord(@PathVariable("pageNo") int pageNo, 
			@PathVariable("pageSize") int pageSize, @RequestBody StockRecord stockRecord, HttpServletRequest request){
		Map<String,Object> params = new HashMap<>();
		params.put("stockRecord", stockRecord);
		params.put("pageNo", pageNo);
		params.put("pageSize", pageSize);
		int rows = stockRecordQueryService.queryStockRecordCnt(stockRecord);
		if(rows > 0){
			params.put("totalPage", Math.ceil((double)rows/pageSize));
			params.put("totalRecord", rows);
			List<StockRecord> list = stockRecordQueryService.queryStockRecordByParam(params);
			params.put("stockRecordList", list);
		}
		return params;
	}
	
}
